function t(t) {
    if (Array.isArray(t)) {
        for (var a = 0, e = Array(t.length); a < t.length; a++) e[a] = t[a];
        return e;
    }
    return Array.from(t);
}

Page({
    data: {
        detail: {},
        mail: !1,
        sms: !1,
        iphone_x: !1,
        refund_address: [],
        rules: !1,
        intergral: !1,
        keyword: "",
        refund_time: !1,
        send_type: !1,
        change_name: !1,
        delete_time: !1,
        confirm_time: !1,
        pay_type: !1,
        sendType: null,
        online_pay: !1,
        balance: !1,
        huodao: !1,
        sms_status: !1,
        mail_status: !1,
        page_loading: !0,
        actions: [ {
            name: "取消",
            color: "#666666"
        }, {
            name: "确认",
            color: "#446dfd",
            loading: !1
        } ],
        address_name: !1
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    onLoad: function(t) {
      this.getList()
      var aa = wx.getSystemInfoSync();
      if (aa.model) {
        aa.model.indexOf("iphone_x") > -1 && this.setData({
          iphone_x: !0
        })
      }
        getApp().page.onLoad(this, t);
    },
    changeLogo: function() {
        var t = this;
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                getApp().iView.$Toast({
                    type: "loading",
                    duration: 0
                });
                var e = a.tempFilePaths;
                wx.uploadFile({
                    url: getApp().apiUrl.upload.file,
                    filePath: e[0],
                    name: "file",
                    formData: {
                        user: "test"
                    },
                    success: function(a) {
                        var e = JSON.parse(a.data);
                        0 == e.code && (t.data.detail.setting.logo = e.data.url, t.setData({
                            detail: t.data.detail
                        }), t.submit());
                    }
                });
            }
        });
    },
    changeRule: function() {
        this.setData({
            rules: !this.data.rules,
            keyword: this.data.detail.setting.integration
        });
    },
    orderText: function () {
      this.setData({
        order_text: !this.data.order_text,
        keyword: this.data.detail.setting.order_text
      });
    },
    smsSwitch: function(t) {
        var a = this.data.sms;
        t.detail.value ? a.status = "1" : a.status = "0", this.setData({
            sms: a
        }), this.submit();
    },
    mailSwitch: function(t) {
        var a = this.data.mail;
        t.detail.value ? a.status = "1" : a.status = "0", this.setData({
            mail: a
        }), this.submit();
    },
    handleClose: function() {
      this.data.detail.setting.integration = this.data.keyword, this.setData({
            detail: this.data.detail
        }), this.submit();
    },
    orderTextClose: function () {
      this.data.detail.setting.order_text = this.data.keyword, this.setData({
        detail: this.data.detail
      }), this.submit();
    },
    changeRefund: function() {
        this.setData({
            refund_time: !this.data.refund_time,
            keyword: this.data.detail.setting.after_sale_time
        });
    },
    refund_change: function(a) {
        var e = a.detail.index;
        0 === e ? this.changeRefund() : 1 === e && ([].concat(t(this.data.actions))[1].loading = !0, 
        this.data.detail.setting.after_sale_time = this.data.keyword, this.setData({
            detail: this.data.detail
        }), this.submit());
    },
    changeConfirm: function() {
        this.setData({
            confirm_time: !this.data.confirm_time,
            keyword: this.data.detail.setting.delivery_time
        });
    },
    change_confirm: function(a) {
        var e = a.detail.index;
        0 === e ? this.changeConfirm() : 1 === e && ([].concat(t(this.data.actions))[1].loading = !0, 
        this.data.detail.setting.delivery_time = this.data.keyword, this.setData({
            detail: this.data.detail
        }), this.submit());
    },
    toChangeIntergral: function() {
        this.setData({
            intergral: !this.data.intergral,
            keyword: this.data.detail.setting.integral
        });
    },
    intergral_change: function(a) {
        var e = a.detail.index;
        0 === e ? this.toChangeIntergral() : 1 === e && ([].concat(t(this.data.actions))[1].loading = !0, 
        this.data.detail.setting.integral = this.data.keyword, this.setData({
            detail: this.data.detail
        }), this.submit());
    },
    toChangeName: function() {
        this.setData({
            change_name: !this.data.change_name,
            keyword: this.data.detail.setting.name
        });
    },
    toChangeAddress: function () {
      this.setData({
        address_name: !this.data.address_name,
        keyword: this.data.detail.address ? this.data.detail.address.address :'',
        name: this.data.detail.address ?  this.data.detail.address.name : '',
        mobile: this.data.detail.address ? this.data.detail.address.mobile : ''
      });
    },
    change_name: function() {
        this.data.keyword ? (this.data.detail.setting.name = this.data.keyword, this.setData({
            detail: this.data.detail
        }), this.submit()) : wx.showToast({
            title: "商城名称不得为空",
            icon:'none'
        });
    },
    change_address: function () {
      var data = {
        address: this.data.keyword ? this.data.keyword : '',
        name: this.data.name ? this.data.name : '',
        mobile: this.data.mobile ? this.data.mobile : '',
        id: this.data.detail.address ? this.data.detail.address.id : 0
      },t=this;
      if (!data.address || !data.name || !data.mobile) {
        wx.showToast({
          title: "请补全收货信息",
          icon: 'none'
        });
      }else {
        wx.showLoading()
        getApp().request({
          url: getApp().api.admin.setting.address,
          data: data,
          method: "post",
          success: function (a) {
            wx.hideLoading(), 0 == a.code ? (wx.showToast({
              title: a.msg,
              icon: 'none'
            }), t.setData({
              address_name:!1
            }), t.getSetting()) : wx.showToast({
              title: a.msg,
              icon: 'none'
            });
          },
          file: function (t) {
            wx.showToast({
              title: t.msg,
              icon: 'none'
            });
          }
        });
      }
    },
    toChangeDelete: function() {
        this.setData({
            delete_time: !this.data.delete_time,
            keyword: this.data.detail.setting.over_day
        });
    },
    change_delete: function(a) {
        var e = a.detail.index;
        0 === e ? this.toChangeDelete() : 1 === e && ([].concat(t(this.data.actions))[1].loading = !0, 
        this.data.detail.setting.over_day = this.data.keyword, this.setData({
            detail: this.data.detail
        }), this.submit());
    },
    choose_send: function() {
        this.setData({
            send_type: !this.data.send_type,
            sendType: this.data.detail.setting.send_type
        });
    },
    send_change: function(a) {
        var e = a.detail.index;
        0 === e ? this.setData({
            send_type: !this.data.send_type,
            sendType: null
        }) : 1 === e && ([].concat(t(this.data.actions))[1].loading = !0, this.data.detail.setting.send_type = this.data.sendType, 
        this.setData({
            detail: this.data.detail
        }), this.submit());
    },
    choose: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            sendType: a
        });
    },
    choose_pay: function() {
        var t = !1, a = !1, e = !1;
        var that = this;
        this.setData({
          pay_type: !that.data.pay_type,
          wechat: that.data.detail.payment_type.wechat,
          balance: that.data.detail.payment_type.balance,
          alipay: that.data.detail.payment_type.alipay,
          huodao: that.data.detail.payment_type.huodao
        });
    },
    choose_type: function(t) {
        var a = t.currentTarget.dataset.type;
            "wechat" == a && this.setData({
              wechat: !this.data.wechat
        }), "balance" == a && this.setData({
              balance: !this.data.balance
        }), "alipay" == a && this.setData({
              alipay: !this.data.alipay
        }), "huodao" == a && this.setData({
              huodao: !this.data.huodao
        });
    },
    pay_change: function(a) {
        var e = a.detail.index;
        var data = {};
        if(this.data.wechat) {
          data.wechat = 1;
        }
        if (this.data.alipay) {
          data.alipay = 1;
        }
        if (this.data.balance) {
          data.balance = 1;
        }
        if (this.data.huodao) {
          data.huodao = 1;
        }
        this.data.detail.setting.payment_type = data;
        this.setData({
            detail: this.data.detail
        }), this.submit();
    },
    input: function(t) {
        var a = void 0;
      a = this.data.rules || this.data.order_text || this.data.change_name || this.data.address_name ? t.detail.value : +t.detail.value, 
        this.setData({
            keyword: a.toString()
        });
    },
    
    input_name: function (t) {
      var a = void 0;
      a = this.data.rules || this.data.change_name || this.data.address_name ? t.detail.value : +t.detail.value,
        this.setData({
          name: a.toString()
        });
    },
    input_mobile: function (t) {
      var a = void 0;
      a = this.data.rules || this.data.change_name || this.data.address_name ? t.detail.value : +t.detail.value,
        this.setData({
          mobile: a.toString()
        });
    },
    submit: function() {
        var t = this, a = JSON.stringify(this.data.detail.setting);
        wx.showLoading({
            content: "加载中"
        });
        var e = {
            name: this.data.detail.name,
            setting: a
        };
        this.data.sms && (e.sms = this.data.sms.status), this.data.mail && (e.mail = this.data.mail.status), 
        getApp().request({
            url: getApp().api.admin.setting.setting,
            data: e,
            method: "post",
            success: function (a) {
              wx.hideLoading(), 0 == a.code ? (wx.showToast({
                title: a.msg,
                icon : 'none'
              }), t.setData({
                rules: !1,
                intergral: !1,
                keyword: "",
                refund_time: !1,
                send_type: !1,
                change_name: !1,
                delete_time: !1,
                confirm_time: !1,
                pay_type: !1
              }), t.getSetting()) : wx.showToast({
                title: a.msg,
                icon: 'none'
              });
            },
            file: function(t) {
              wx.showToast({
                title: t.msg,
                icon: 'none'
              });
            }
        });
    },
    getList: function() {
        // var t = this;
        // wx.showLoading({
        //     title: "加载中"
        // }), getApp().request({
        //     url: getApp().api.admin.setting.index,
        //     method: "get",
        //     success: function(a) {
        //       wx.hideLoading(), 0 == a.code ? (t.setData({
        //         refund_address: a.data.data.list
        //       }), t.getSetting()) : wx.showToast({
        //         title: a.data.msg,
        //         icon: 'none'
        //       });
        //     },
        //     file: function (t) {
        //       wx.showToast({
        //         title: t.msg,
        //         icon:'none'
        //       });
        //     }
        // });
        this.getSetting();
    },
    getSetting: function() {
        var t = this;
        wx.showLoading({
            content: "加载中"
        }), getApp().request({
            url: getApp().api.admin.setting.index,
            method: "get",
          success: function (a) {
            if (wx.hideLoading(), 0 == a.code) {
              var e = a.data.detail, i = a.data.mail, s = a.data.sms, n = !1;
              i && 1 == i.status && (n = !0);
              var d = !1;
              s && 1 == s.status && (d = !0), t.setData({
                detail: e,
                mail: i,
                mail_status: n,
                sms_status: d,
                sms: s
              });
            } else wx.showToast({
              title: a.msg,
              icon: 'none'
            });
          },
          file: function (t) {
            wx.showToast({
              title: t.msg,
              icon: 'none'
            });
          }
        });
    }
});